package y2015.date0912am.创建线程;

import org.junit.jupiter.api.Test;

public class StudyCreatThread {

    @Test
    public void main() throws Exception {
        /**
         * 创建线程1
         */
        Thread runer1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(System.currentTimeMillis() + "线程1");
            }
        });
        /**
         * 创建线程2
         */
        Runnable runnable2 = new Runnable() {
            @Override
            public void run() {
                System.out.println(System.currentTimeMillis() + "线程2");
            }
        };
        Thread runer2 = new Thread(runnable2);

        /**
         * 创建线程3
         */
        Thread runer3 = new Thread() {
            @Override
            public void run() {
                System.out.println(System.currentTimeMillis() + "线程3");
            }

        };

        //设置线程优先级
        /**
         * 	public static final int MAX_PRIORITY 10
         public static final int MIN_PRIORITY 1
         public static final int NORM_PRIORITY 5 默认优先级
         */
        runer1.setPriority(Thread.MIN_PRIORITY);//优先级范围1~10
        runer2.setPriority(Thread.MAX_PRIORITY);//10
        runer3.setPriority(7);

        //虽然设置线程2为最大优先级，因为线程3和1先start，所以仍然可能被线程3抢占
        //执行线程
        runer3.start();
        runer1.start();
        runer2.start();
    }

}

